package com.liuceng.zen.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.liuceng.zen.pojo.domain.MemberOperationNotification;
import com.liuceng.zen.pojo.form.MemberOperationNotificationForm;
import com.liuceng.zen.service.MemberOperationNotificationService;

@Controller
public class MessageAction {

  @Autowired
  private MemberOperationNotificationService memberOperationNotificationService;

  @RequestMapping(value = "member_operation_notification/edit/{id}", method = RequestMethod.POST)
  public String doedit(@PathVariable Integer id,
      @ModelAttribute("form") MemberOperationNotificationForm form) {
    if (form.getStatus() != null && form.getStatus() == MemberOperationNotificationForm.SUCCESS) {
      MemberOperationNotification m = new MemberOperationNotification();
      m.setId(id);
      m.setDataFlag(MemberOperationNotificationForm.SUCCESS);
      memberOperationNotificationService.update(m);
      form.setMessage("操作成功");
    } else {
      form.setMessage("操作失败");
    }
    return "message/success";
  }

  @RequestMapping(value = "member_operation_notification/edit/{id}", method = RequestMethod.GET)
  public String edit(@PathVariable Integer id,
      @ModelAttribute("form") MemberOperationNotificationForm form) {
    form.setStatus(MemberOperationNotificationForm.SUCCESS);
    return "message/edit";
  }
}
